<!--
 * @Description: 定时任务 - 主页面
 * @Author: DSY
 * @Date: 2022-03-19 22:45:22
 * @LastEditors: DHL
 * @LastEditTime: 2022-11-22 17:54:42
-->
<template>
  <tw-layout @refresh="handleRefresh" @search="handleSearch" @reset="handleReset">
    <!-- 按钮组 -->
    <template #btns>
      <el-button
        class="item"
        type="danger"
        :loading="loadingByDel"
        :disabled="isSelectRows"
        @click="handleDelete()"
      >
        <svg-icon iconClass="delete"></svg-icon>
        批量删除
      </el-button>

      <el-button class="item" type="primary" @click="handleOpenForm('add')">
        <svg-icon iconClass="plus"></svg-icon>
        新增
      </el-button>
    </template>

    <!-- 查询表单 -->
    <template #header>
      <el-form ref="searchFormRef" :model="searchForm" label-width="90px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="任务编码">
              <el-input v-model="searchForm.code" clearable placeholder="请输入任务编码"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="任务名称">
              <el-input v-model="searchForm.name" clearable placeholder="请输入任务名称"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="任务分组">
              <el-input
                v-model="searchForm.groupName"
                clearable
                placeholder="请输入任务分组"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="调用目标">
              <el-input
                v-model="searchForm.invokeTarget"
                clearable
                placeholder="请输入调用目标字符串"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="表达式">
              <el-input
                v-model="searchForm.cronExpression"
                clearable
                placeholder="请输入表达式"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="计划策略">
              <el-select v-model="searchForm.misfirePolicy" clearable placeholder="请选择计划策略">
                <tw-dic dicKey="TWB_QUARTZ_JOB_MISFIREPOLICY"></tw-dic>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="并发执行">
              <el-select v-model="searchForm.concurrent" clearable placeholder="请选择并发执行">
                <tw-dic dicKey="TWB_QUARTZ_JOB_CONCURRENT"></tw-dic>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="状态">
              <el-select v-model="searchForm.status" clearable placeholder="请选择状态">
                <tw-dic dicKey="TWB_QUARTZ_JOB_STATUS"></tw-dic>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </template>

    <!-- 数据表格 -->
    <tw-table
      ref="tableRef"
      :loading="loading"
      :options="tableOptions"
      :events="tableEvents"
      :data="tableData"
      @search="searchList"
    >
      <!-- 是否允许并发 -->
      <template #concurrent="{ row }">
        <vxe-switch
          v-model="row.concurrent"
          open-label="允许"
          open-value="1"
          close-label="禁止"
          close-value="2"
          @change="handleUpdateById(row)"
        ></vxe-switch>
      </template>
      <!-- 状态 -->
      <template #status="{ row }">
        <vxe-switch
          v-model="row.status"
          open-label="正常"
          open-value="1"
          close-label="暂停"
          close-value="2"
          @change="handleChangeStatus(row)"
        ></vxe-switch>
      </template>
      <template #action="{ row }">
        <el-button link type="warning" @click="handleOpenForm('edit', row)">编辑</el-button>
        <el-button link type="danger" @click="handleDelete(row)">删除</el-button>
        <el-button link type="success" @click="handleRunOnceJob(row)">立即执行一次</el-button>
      </template>
    </tw-table>

    <quartzJobForm ref="formRef" @refreshTableData="handleRefresh"></quartzJobForm>
  </tw-layout>
</template>

<script src="./useIndex.ts"></script>

<style scoped lang="scss"></style>
